package com.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class TestAspect {

    //定义一个连接点(SpringAop对方法进行切入)
    @Pointcut("execution(* com.service.*.*(..))")
    public void put(){}

    @Around("put()")
    public Object aroundMethod(ProceedingJoinPoint pjp){
        //让目标方法执行(可以指定何时执行)
        try {
            return pjp.proceed();//目标方法执行,返回结果
        }catch (Throwable e){
            e.printStackTrace();
        }
        return null;
    }

    @AfterReturning("put()")
    public  void returningMethod(){
        System.out.println("再方法正常返回后执行的通知");
    }

    @Before("put()")
    public void beforeMethod(){
        System.out.println("前置通知");
    }

    @AfterThrowing("put()")
    public void thr(){
        System.out.println("异常执行的通知");
    }

    @After("put()")
    public void afterMethod(){
        System.out.println("在目标方法执行后做处理");
    }
}
